/**
 * Author:yuiop
 * Date:2022/9/22 14:45
 */
package com.devops.admin.config;

import com.devops.admin.config.bean.AliyunAccountDataSourceProperties;
import com.devops.admin.config.bean.AliyunAccountProperties;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public abstract class AliyunAccountDataSourceContext implements ApplicationContextAware {
    public static final String FIELD_DATASOURCE_NAME = "dataSourceName";

    protected ApplicationContext applicationContext;

    protected String dataSourceName;

    public void setDataSourceName(String dataSourceName) {
        this.dataSourceName = dataSourceName;
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    /**
     * 通过数据源名称获取该数据源对应的aliyun配置
     */
    protected AliyunAccountProperties getAliyunAccountProperties() {
        AliyunAccountDataSourceProperties dataSourceProperties = applicationContext.getBean(AliyunAccountDataSourceProperties.class);
        // 通过数据源名称获取application配置文件中配置的该数据源的redis-properties
        return dataSourceProperties.getDataSource().get(dataSourceName);
    }
}
